package com.gift.recommendation.util;

import com.gift.recommendation.config.GiftProperties;
import com.gift.recommendation.modules.login.dto.EmailEntityExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

/**
 * @author zzh <2658137258@qq.com>
 * @date 2022/12/29
 */
@Component
public class SendEmail {
    @Autowired
    private JavaMailSender mailSender;

    @Autowired
    private GiftProperties giftProperties;

    public void sendEmails(EmailEntityExt emailEntity){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(emailEntity.getEmail());
        message.setFrom(giftProperties.getSendEmail());
        message.setSubject("礼物赠送系统通知");
        message.setText(emailEntity.getData());
        try{
            mailSender.send(message);
        }catch (Exception e){
            throw new RuntimeException("发送失败，请检查电子邮箱是否正确");
        }

    }
}
